package com.example.mulittenantdemo.config;

import com.example.mulittenantdemo.dto.OssFile;
import com.example.mulittenantdemo.service.OssTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Autowired
    private OssTemplate ossTemplate;

    @PostMapping("/upload")
    public OssFile handleFileUpload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return null;
        }
        OssFile test = ossTemplate.upLoadFile("test", file.getOriginalFilename(), file);
        return test;

    }
}
